package webClient.ChatEngine;

import java.io.IOException;
import java.net.InetAddress;

import javax.swing.JOptionPane;

import webClient.UserInterfaceApplet.buddyList;
import webClient.UserInterfaceClasses.Login;

import communication.*;

public class RequestSender {

	InetAddress serverIP;
	int serverPort;
	InetAddress clientIP;
	int clientPort;
	
	public static RequestSender serverSender;
	
	public RequestSender(InetAddress serverIP, int serverPort, InetAddress clientIP, int clientPort){
		this.serverIP = serverIP;
		this.serverPort = serverPort;
	}
	
	public static void setUpServer(InetAddress serverIP, int serverPort, InetAddress clientIP, int clientPort){
		serverSender = new RequestSender(serverIP, serverPort, clientIP, clientPort);
		System.out.println("Set up the server!");
	}
	
	public static RequestSender getServerSender(){
		return serverSender;
	}
	
	public void sendMessage(String user, String message){}
	public void newAccount(String username, String password){}
	
	public void signOn(String username, String password){
		sendRequest(new SignOnRequest(username, password, buddyList.clientIP, buddyList.clientPort));
	}
	public void signOff(){}
	
	
	
	
	
	public void sendRequest(Request r){

		try {
			ClientConnection connection = new ClientConnection(serverIP, serverPort);
			connection.writeRequest(r);
			connection.close();
		} catch (IOException e) {
			e.printStackTrace();
			System.out.println("Send Request failed.");
		}
		
	}
}
